<?php
class useraddressdao extends CI_Model{
	function __construct()
	{
		// Call the Model constructor
		parent::__construct();
	}

	public function getbyid($id){
		$this->db->select('*');
		$this->db->from('user_addresses');
		$this->db->where('user_id',$id);
		$query = $this->db->get();
		$user_address = $query->row();
		return $user_address;
	}
	
	public function get_all(){
		$this->db->select('*');
		$this->db->from('user_addresses');
		$query = $this->db->get();
		$user_addresses = $query->result();
		return $user_addresses;
	}
	
	public function insert($user_id,$street_id,$remaining_address,$user_branch_phone){
		$data = array(
				'user_id' => $user_id,
				'user_remaining_address' => $remaining_address,
				'street_id' => $street_id,
				'user_branch_phone' => $user_branch_phone
		);
		$str = $this->db->insert_string('user_addresses', $data);
		$res = $this->db->query($str);
		return $str;
	}
	
	public function del($user_id) {
		if (intval($user_id) > 0) {
			$this->db->where('user_id', $user_id);
			$this->db->delete('user_addresses');
			return ($this->db->affected_rows() == 1) ? TRUE : FALSE;
		}
		return false;
	}
}
?>